<?php

namespace app\utils;

class DateUtil
{
    //获取后两天
    public static function twoDay()
    {
        $totalDay = date('t');//当月总天数
        $day = date('d');//当前日
        $selectDay = $day + 2;
        if ($selectDay <= $totalDay) {
            $repaymentDay = $selectDay;
        } else if (1 == ($selectDay - $day)) {
            $repaymentDay = 1;
        } else {
            $repaymentDay = 2;
        }
        return $repaymentDay;
    }
    public static function oneDay()
    {
        $totalDay = date('t');//当月总天数
        $day = date('d');//当前日
        $selectDay = $day + 1;
        if ($selectDay <= $totalDay) {
            $repaymentDay = $selectDay;
        } else if (1 == ($selectDay - $day)) {
            $repaymentDay = 1;
        } else {
            $repaymentDay = 2;
        }
        return $repaymentDay;
    }

    //获取前两天
    public static function backTwoDay()
    {
        $lastMonth = strtotime('last month');
        $daysInLastMonth = date('t', $lastMonth);
        $day = date('d');//当前日
        $selectDay = $day - 2;
        if ($selectDay >= 0) {
            $repaymentDay = $selectDay;
        } else if (-1 == $selectDay) {
            $repaymentDay = $daysInLastMonth;
        } else {
            $repaymentDay = $daysInLastMonth - 1;
        }
        return $repaymentDay;
    }

    //获取前两天
    public static function backOneDay()
    {
        $lastMonth = strtotime('last month');
        $daysInLastMonth = date('t', $lastMonth);
        $day = date('d');//当前日
        $selectDay = $day - 1;
        if ($selectDay >= 0) {
            $repaymentDay = $selectDay;
        } else if (-1 == $selectDay) {
            $repaymentDay = $daysInLastMonth;
        } else {
            $repaymentDay = $daysInLastMonth - 1;
        }
        return $repaymentDay;
    }
}